#
# Copyright 2005 The Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# Note: This makefile depends on 4 environment variables to funtion correctly:
# a) JAVA_HOME
# b) OS_NAME
# c) OS_ARCH
# d) LIBPLEIADES_BUILD_DIR
# All these are passed by build.xml.
#

CC = gcc
LD = gcc
CFLAGS =  -g -Wall -O2 -fPIC -DDEBUG
#LDFLAGS = -L$(JAVA_HOME)/jre/lib/$(OS_ARCH)/server -ljvm -shared -m32 -Wl,-x
LDFLAGS= -L$(JAVA_HOME)/jre/lib/$(OS_ARCH)/server -ljvm -shared -Wl,-x
PLATFORM = $(shell echo $$OS_NAME | tr [A-Z] [a-z])
#CPPFLAGS = -m32 -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(PLATFORM)
CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(PLATFORM)

LIB_NAME = pleiades
SO_NAME = lib$(LIB_NAME).so
SO_TARGET = $(LIBPLEIADES_BUILD_DIR)/lib$(LIB_NAME).so.$(SHLIB_VERSION)
SO = $(LIBPLEIADES_BUILD_DIR)/$(SO_NAME)

RM = rm -rf
LINK = ln -sf
DOXYGEN = doxygen

CSRC = \
	pleiades.c \
	jni_helper.c \
	com_nhncorp_nebula_pleiades_client_NativeLockEventHandler.c \
	$(NONE)

COBJS = $(addprefix $(LIBPLEIADES_BUILD_DIR)/,$(patsubst %,%.o,$(basename $(CSRC))))

PLEIADES_TEST = $(LIBPLEIADES_BUILD_DIR)/pleiades_test

all: $(SO_TARGET) $(PLEIADES_TEST)

$(SO_TARGET): $(COBJS)
	$(LD) $(LDFLAGS) -o $(SO_TARGET) -Wl,-soname,lib$(LIB_NAME).so.$(SHLIB_VERSION) $(COBJS) \
	&& $(LINK) $(SO_TARGET) $(SO)

$(LIBPLEIADES_BUILD_DIR)/%.o: %.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

$(PLEIADES_TEST): pleiades_test.c CuTest.c
	$(CC) $(CPPFLAGS) pleiades_test.c CuTest.c -Wl,-rpath,. -L$(LIBPLEIADES_BUILD_DIR) -l$(LIB_NAME) -o $@

clean:
	$(RM) $(LIBPLEIADES_BUILD_DIR)/*

doc:
	$(DOXYGEN) docs/Doxyfile

test: $(HDFS_TEST)
	./tests/test-libhdfs.sh

# vim: sw=4: ts=4: noet

